small
    | | 
    a(href='#sustainable-per-domain') Per domain
    | &nbsp;|&nbsp;
    a(href='#dirtiest-assets') Dirtiest assets
    | &nbsp;|&nbsp;
    a(href='#sustainible-per-content-type') Per Content Type
    | &nbsp;|&nbsp;

h1 Sustainable Web

- let sustainable = pageInfo.data.sustainable.run ? pageInfo.data.sustainable.run : pageInfo.data.sustainable.pageSummary

p The sustainable metrics is calculated using 
    a(href='https://github.com/thegreenwebfoundation/co2.js') @tgwf/co2
    | &nbsp;version #{sustainable.co2Version} using model #{options.sustainable.model} #{options.sustainable.model === 'swd' ? 'version ' + options.sustainable.modelVersion : ''}.

p We know that using the internet means using electricity, and because most of that electricity comes from fossil fuels, it means that more data we send, the more fossil fuels we end up burning.

p This is terrible news for the climate, and  
    a(href='https://www.w3.org/2001/tag/doc/ethical-web-principles/') building a sustainable web is the 9th of the W3C's Ethical Web Principles.

p If you build for the web, much of what you know about making sites faster and more accessible also makes them greener. If you're interested in learning more, you can find out at  
    a(href='https://www.thegreenwebfoundation.org') The Green Web Foundation.

if !options.sustainable.pageViews
    p Use
        code --sustainable.pageViews
        | to configure the number of page views and calculate total CO2 emission.

if (sustainable.hostingInfo)
    p #{sustainable.hostingInfo.url} #{sustainable.hostingInfo.green === true ? 'is hosted green! This means the servers running the site use green energy' : 'does not appear to be running on green energy.'}

    p This information comes from The Green Web Foundation's datasets, which are published as open data. If you have questions, corrections or want to use this data yourself, please visit 
    a(href='https://www.thegreenwebfoundation.org') The Green Web Foundation website.

- const co2FirstParty = sustainable.co2FirstParty.median || sustainable.co2FirstParty
- const co2ThirdParty = sustainable.co2ThirdParty.median === 0 ? 0 : sustainable.co2ThirdParty.median || sustainable.co2ThirdParty
- const co2PerPageView = sustainable.co2PerPageView.median || sustainable.co2PerPageView
- const totalCO2 = sustainable.totalCO2.median || sustainable.totalCO2
- const totalTransfer = sustainable.totalTransfer.median || sustainable.totalTransfer
- const firstPartyTransferPerPage = sustainable.firstPartyTransferPerPage.median || sustainable.firstPartyTransferPerPage
- const thirdPartyTransferPerPage =  sustainable.thirdPartyTransferPerPage === undefined ? 0 : sustainable.thirdPartyTransferPerPage.median || sustainable.thirdPartyTransferPerPage

table
    tr
        th Page views
        th Estimated CO2 emissions #{sustainable.co2PerPageView.median ?  '(median)':''}
        th Transfer Size
    tr
        td 1 page view total
        td #{h.co2(co2PerPageView)}
        td #{h.size.format(totalTransfer)}

    tr
        td 1 page view first party
        td #{h.co2(co2FirstParty)} (#{Number(co2FirstParty / (co2FirstParty + co2ThirdParty) * 100).toFixed(2)} %)
        td #{h.size.format(firstPartyTransferPerPage)}
    tr
        td 1 page view third party
        td #{h.co2(co2ThirdParty)} (#{Number(co2ThirdParty / (co2FirstParty + co2ThirdParty) * 100).toFixed(2)} %)
        td #{h.size.format(thirdPartyTransferPerPage)}

    if (options.sustainable && options.sustainable.pageViews)
        tr
            td #{options.sustainable.pageViews.toLocaleString()} page views
            td #{h.co2(totalCO2)}
            td #{h.size.format(totalTransfer * options.sustainable.pageViews)}
- sustainable = pageInfo.data.sustainable.pageSummary ? pageInfo.data.sustainable.pageSummary.firstRun : sustainable
a#sustainable-per-domain
h2 Per domain
    if pageInfo.data.sustainable.pageSummary
        | (first run)
table
    thead
        tr
            th Domain
            th Estimated CO2 emissions
            th Transfer Size
    each data in sustainable.co2PerDomain
        tr
            td #{data.domain} 
                - if (sustainable.hostingGreenCheck.indexOf(data.domain) > -1)
                    span(class='label normal ok') green
            - const percentage = (data.co2 / co2PerPageView) * 100
            td.number #{h.co2(data.co2)} (#{Number(percentage).toFixed(2)} %)
            td.number #{h.size.format(data.transferSize)}
a#dirtiest-assets
h2 Dirtiest assets
    if pageInfo.data.sustainable.pageSummary
        | (first run)
table
    thead
        tr
            th Asset
            th Estimated CO2 emissions
            th Transfer Size
    each resource in sustainable.dirtiestResources
        tr
            td.url.assetsurl(data-title='URL')
                a(href=resource.url)= h.shortAsset(resource.url)
            - const percentage = (resource.co2 / co2PerPageView) * 100
            td.number #{h.co2(resource.co2)} (#{Number(percentage).toFixed(2)} %)
            td.number= h.size.format(resource.transferSize)
a#sustainible-per-content-type
h2 Per Content Type
    if pageInfo.data.sustainable.pageSummary
        | (first run)
table
    thead
        tr
            th Content Type
            th Estimated CO2 emissions
            th Transfer Size
    each t in sustainable.co2PerContentType
        tr
            td #{t.type}
            - const percentage = (t.co2 / co2PerPageView) * 100
            td.number #{h.co2(t.co2)} (#{Number(percentage).toFixed(2)} %)
            td.number= h.size.format(t.transferSize)
